
---------------------------------------------------
-- Global vars
---------------------------------------------------

Cooldowns_SavedVars = {};

---------------------------------------------------
-- Local vars
---------------------------------------------------


---------------------------------------------------
-- Cooldowns.OptionsSetup
---------------------------------------------------
function Cooldowns.OptionsSetup()
	if (not Cooldowns_SavedVars.FontHeight) then
		Cooldowns.OptionsDefault();
	end
	InterfaceOptions_AddCategory(Cooldowns_OptionsPanel);
end


---------------------------------------------------
-- Cooldowns.OptionsDefault
---------------------------------------------------
function Cooldowns.OptionsDefault()
	Cooldowns_SavedVars.MainColor = Cooldowns.CopyColors(Cooldowns.DefaultMainColor);
	Cooldowns_SavedVars.FlashColor = Cooldowns.CopyColors(Cooldowns.DefaultFlashColor);
	Cooldowns_SavedVars.FontLocation = Cooldowns.DefaultFontLocation;
	Cooldowns_SavedVars.FontFile = Cooldowns.DefaultFontFile;
	Cooldowns_SavedVars.FontHeight = Cooldowns.DefaultFontHeight;
end


---------------------------------------------------
-- Cooldowns.OptionsRefresh
---------------------------------------------------
function Cooldowns.OptionsRefresh()
	Cooldowns_OptionsPanelMainColorNormalTexture:SetVertexColor(Cooldowns_SavedVars.MainColor.r, 
		Cooldowns_SavedVars.MainColor.g, Cooldowns_SavedVars.MainColor.b);
	Cooldowns_OptionsPanelFlashColorNormalTexture:SetVertexColor(Cooldowns_SavedVars.FlashColor.r, 
		Cooldowns_SavedVars.FlashColor.g, Cooldowns_SavedVars.FlashColor.b);
	Cooldowns_OptionsPanelFontLocation:SetText(Cooldowns_SavedVars.FontLocation);
	Cooldowns_OptionsPanelFontLocation:SetCursorPosition(0);
	Cooldowns_OptionsPanelFontFile:SetText(Cooldowns_SavedVars.FontFile);
	Cooldowns_OptionsPanelFontFile:SetCursorPosition(0);
	Cooldowns_OptionsPanelFontHeight:SetNumber(Cooldowns_SavedVars.FontHeight);
	Cooldowns_OptionsPanelFontHeight:SetCursorPosition(0);
end


---------------------------------------------------
-- Cooldowns.OptionsOkay
---------------------------------------------------
function Cooldowns.OptionsOkay()
	Cooldowns_SavedVars.MainColor.r, Cooldowns_SavedVars.MainColor.g, 
		Cooldowns_SavedVars.MainColor.b 
		= Cooldowns_OptionsPanelMainColorNormalTexture:GetVertexColor();
	Cooldowns_SavedVars.FlashColor.r, Cooldowns_SavedVars.FlashColor.g, 
		Cooldowns_SavedVars.FlashColor.b 
		= Cooldowns_OptionsPanelFlashColorNormalTexture:GetVertexColor();
	Cooldowns_SavedVars.FontLocation = Cooldowns_OptionsPanelFontLocation:GetText();
	Cooldowns_SavedVars.FontFile = Cooldowns_OptionsPanelFontFile:GetText();
	Cooldowns_SavedVars.FontHeight = Cooldowns_OptionsPanelFontHeight:GetNumber();
	
	if (Cooldowns_SavedVars.FontHeight < 4) then
		Cooldowns_SavedVars.FontHeight = 4;
	end
	
	if (Cooldowns_SavedVars.FontHeight > 72) then
		Cooldowns_SavedVars.FontHeight = 72;
	end
	
	Cooldowns.UpdateCooldowns();
end


---------------------------------------------------
-- Cooldowns.SwatchOnClick
---------------------------------------------------
function Cooldowns.SwatchOnClick(self)
	local info = {};
	info.extraInfo = _G[self:GetName().."NormalTexture"];
	info.r, info.g, info.b = info.extraInfo:GetVertexColor();
	info.swatchFunc = Cooldowns.SetColor;
	OpenColorPicker(info);
end


---------------------------------------------------
-- Cooldowns.SetColor
---------------------------------------------------
function Cooldowns.SetColor()
	if (not ColorPickerFrame:IsVisible()) then
		ColorPickerFrame.extraInfo:SetVertexColor(ColorPickerFrame:GetColorRGB());
	end
end


---------------------------------------------------
-- Cooldowns.UpdateCooldowns
---------------------------------------------------
function Cooldowns.UpdateCooldowns()
	local index, value;
	
	for index, value in ipairs(Cooldowns.CounterFrames) do
		Cooldowns.UpdateFont(_G[value.."Text"]);
	end
end


---------------------------------------------------
-- Cooldowns.UpdateFont
---------------------------------------------------
function Cooldowns.UpdateFont(object)
	object:SetFont(Cooldowns_SavedVars.FontLocation.."\\"..Cooldowns_SavedVars.FontFile, 
		Cooldowns_SavedVars.FontHeight);
end


---------------------------------------------------
-- Cooldowns.CopyColors
---------------------------------------------------
function Cooldowns.CopyColors(object)
	local tbl = {};
	
	tbl.r = object.r;
	tbl.g = object.g;
	tbl.b = object.b;
	
	return tbl;
end
